package com.jiamao.goplay.immsg;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.jiamao.goplay.R;
import com.jiamao.goplay.ui.discover.AddrDetailFragment;
import com.jiamao.goplay.util.StringUtils;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nim.uikit.common.util.sys.TimeUtil;

import me.goldze.mvvmhabit.base.AppManager;
import me.goldze.mvvmhabit.utils.BlurTransformation;
import me.goldze.mvvmhabit.utils.KLog;

public class MsgViewHolderCrops extends MsgViewHolderMatch {
    public MsgViewHolderCrops(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }


    @Override
    public void bindContentView() {
        super.bindContentView();
        MatchAttachment attachment = (MatchAttachment)message.getAttachment();
        tvName.setText(attachment.getPlaceName());
        tvCity.setText(attachment.getCity());
        tvNums.setText(StringUtils.formatBigNum(attachment.InterestUserNum)+"人想去");

        if (attachment.InviteUid.equals( NimUIKit.getAccount())){
            tvTitle.setText(attachment.InviteDesc);
        }else {
            tvTitle.setText(attachment.InviteesDesc);
        }
       ;

        tvTime.setText("配对于："+TimeUtil.getTimeShowString(attachment.PairTime*1000,true));

        KLog.d("City:"+attachment.City+" InterestUserNum:"+attachment.InterestUserNum+" PlaceName:"+attachment.PlaceName+"" +
                " Type:"+attachment.Type+" PlaceId:"+attachment.PlaceId+" InviteUid:"+attachment.InviteUid+ " InviteesUid:"+attachment.InviteesUid+" InviteDesc:"+attachment.InviteDesc+
                " InviteesDesc:"+attachment.InviteesDesc+"   PairDesc:"+attachment.PairDesc);

        Glide.with(img.getContext())
                .load(attachment.PlaceCover)
                .placeholder(R.mipmap.icon_img_userhead_loading) //占位符 也就是加载中的图片，可放个gif
                .error(R.mipmap.icon_img_userhead_loading_error) //失败图片
                // .apply(new RequestOptions().placeholder(placeholderRes))
                .into(img);

        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!TextUtils.isEmpty(attachment.PlaceId)){

                    Bundle bds = new Bundle();
                    bds.putString("id",attachment.PlaceId);
                    ComponentName componetName = new ComponentName("com.jiamao.goplay","com.jiamao.goplay.base.LibContainerActivity");
                    Intent intent = new Intent();
                    intent.putExtra("fragment", AddrDetailFragment.class.getCanonicalName());
                    intent.putExtra("bundle", bds);
                    intent.setComponent(componetName);
                    if ( AppManager.getAppManager().currentActivity() !=null){
                        AppManager.getAppManager().currentActivity().startActivity(intent);
                    }

                }


            }
        });
    }

    @Override

    protected String getDisplayText() {


        //实例化一个attachment
        MatchAttachment attachment = (MatchAttachment)message.getAttachment();
        return  "点！";
    }
}
